<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
</head>

<body>
  <p>
    <input type="button" id="bBtn" value="B" style="font-weight:bold" onclick="setBold();" />
    <input type="button" id="" value="获取内容" onclick="getContent();" />
  </p>
  <p>
    <iframe id="editor" width="600px" height="400px" style="border:solid 1px;"></iframe>
  </p>
</body>
<script>
  // http://www.cnblogs.com/keepfool/archive/2011/12/21/2295335.html
  //初始化编辑器
    function init() {
        var ifr = document.getElementById("editor");
        var doc = ifr.contentDocument || ifr.contentWindow.document; // W3C || IE
        doc.designMode = "on";
        doc.contentEditable = true;
        doc.open()
        doc.close()
        doc.write('<html><head><style>body{ margin:3px; word-wrap:break-word; word-break: break-all; }</style></head><body><b>GoodNessEditor</b></body></html>');
        
        var myName = document.createElement('i')
        myName.innerHTML = '杨观勇'
        doc.body.appendChild(myName)

    }

    //设置选定的文本为粗体/正常
    function setBold() {
        var win = document.getElementById("editor").contentWindow;
        win.document.execCommand("Bold", false, null);
        win.focus();
    }

    function getContent () {
      var ifr = document.getElementById("editor");
      var doc = ifr.contentDocument || ifr.contentWindow.document; // W3C || IE
      alert(doc.body.innerHTML);
    }
    init()
</script>

</html>